/**
 * 
 */
package pl.kkalisz.android.model.window;

import java.util.HashMap;

import pl.kkalisz.android.test_activity_1;
import pl.kkalisz.android.model.error.uWindowNotFoundException;
import pl.kkalisz.android.ui.mainmenu.uMainMenuActivity;

import android.app.Activity;
import android.content.Intent;

/**
 * @author kkalisz
 *
 */
public class uWindowResolver {
    
    static HashMap<Integer, Class<? extends Activity>> mWindows = new HashMap<Integer, Class<? extends Activity>>();
    
    public static void init()
    {
       mWindows.put(uWindows.TEST_WINDOW, test_activity_1.class);
       mWindows.put(uWindows.MAIN_MENU_ACTIVITY, uMainMenuActivity.class);
    }
    
    public static void launch(uWindowBuilder abuilder)
    {
        //Intent aInt = new Intent(abuilder.getParrent(), mWindows.get(abuilder.getWindowId()));
        abuilder.getParrent().startActivity(abuilder.getIntent());
        if(abuilder.shouldCloseCurrentWindow()) abuilder.getParrent().finish();
    }
    
    public static Class<? extends Activity> getWindowClass(Integer aWindowId) throws uWindowNotFoundException
    {
        Class<? extends Activity> aClass = mWindows.get(aWindowId);
        if(aClass == null) throw new uWindowNotFoundException(aWindowId);
        return aClass;
    }

}
